/*
 * Copyright (c) 2022  by Junzhao
 * THIS FILE IS PART OF JAVASE Song Huongkang PROJECT
 * All Rights Reserved.
 */

package Collection接口;

public class Person implements Comparable{
    private String name;
    private int age;

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return age == person.age && name.equals(person.name);
    }

    @Override
    public int compareTo(Object o) {
        if (this==o){
            return 0;
        }else if (o instanceof Person){
            Person person = (Person) o;
            return this.age > person.age ? 1:(this.age == person.age ?0:-1);
//            return Integer.compare(this.age, person.age);
        }
        throw  new RuntimeException("输入类型不匹配");
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }
}
